package com.kt.kvw.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.lang.annotation.Annotation;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Desc:
 *
 * @author: keen
 * Date: 2020-07-06
 * Time: 21:18
 */
public class ScopeValidation implements ConstraintValidator<Scope, String> {

    private String[] values;

    @Override
    public void initialize(Scope scope) {
        this.values = scope.values();
    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        return Arrays.stream(values).anyMatch(value -> value.equals(s));
    }
}
